﻿@page "/FolderView/{Text?}"
@using WebFile.Share.Data



@if (IsAuthenticated)
{
    <PageTitle>@Path.GetFileName(Model.Path)</PageTitle>

    <Card>
        <BodyTemplate>
            <h2>
                <i class="fa fa-folder" aria-hidden="true"></i> @Path.GetFileName(Model.Path)
            </h2>
            <p><Button Color="Color.Link" TooltipText="返回到父级文件夹" IsAsync="true" Icon="fa-solid fa-arrow-left" OnClick="@GoBack"></Button> 一个共有 @FolderModels.Count 个文件</p>

        </BodyTemplate>
    </Card>
    <Divider/>
    <Row ItemsPerRow="ItemsPerRow.Four" ColSpan="4">
        @foreach (var item in FolderModels)
        {
            <a href="@item.ToWebUrl()" target="_top">
                <ContextMenuZone>
                    <ContextMenuTrigger>
                        <Card IsShadow="true" class="item">
                            <BodyTemplate>
                                <FileIcon style="font-size: 18px" IconColor="@GetIconColor(item)" Extension="@Path.GetExtension(item.Path)">
                                    <BackgroundTemplate>
                                        <i class="@item.ToFileIcon()"></i>
                                    </BackgroundTemplate>
                                </FileIcon>
                                <h6>@Path.GetFileNameWithoutExtension(item.Path)</h6>
                            </BodyTemplate>
                        </Card>
                    </ContextMenuTrigger>
                    <ContextMenu>
                        <ContextMenuItem Icon="fa-solid fa-file" Text="打开" OnClick="@((_, _) => { return OnOpen(item); })"/>
                        <ContextMenuItem Icon="fa-solid fa-trash" Text="删除" OnClick="@(async (_, _) => await OnDelete(item))"/>
                        <ContextMenuItem Icon="fa-solid fa-cloud-arrow-down" Text="下载" OnClick="@(async (_, _) => await OnDownload(item))"/>
                    </ContextMenu>
                </ContextMenuZone>
            </a>
        }
    </Row>

    <SlideButton Placement="Placement.TopEnd" class="Slide" HeaderText="上传" ShowHeader="true" Icon="fa-solid fa-plus">
        <BodyTemplate>
            <Row ItemsPerRow="ItemsPerRow.Three">
                <ButtonUpload TValue="string" OnChange="@OnUploadFile"
                              ShowUploadFileList="false" BrowserButtonText=""
                              BrowserButtonIcon="fa-solid fa-cloud-arrow-up" BrowserButtonClass="btn-primary">
                </ButtonUpload>
                <Button Icon="fa-solid fa-folder" OnClick="@OnAddFolder"></Button>
            </Row>
        </BodyTemplate>
    </SlideButton>
}
else
{
    <PageTitle>未找到</PageTitle>
    <Empty Image="https://gw.alipayobjects.com/zos/antfincdn/ZHrcdLPrvN/empty.svg" Width="133" Text="暂无数据">
        <Template>
            <Button OnClick="@(() => NavigationManager.NavigateTo(""))">返回主页</Button>
        </Template>
    </Empty>
}

<style>
    .item{
        height: 200px;
        width: 200px;
    }
    .Slide{
        position:fixed; bottom:0; right: 0;
    }
</style>